
var base_num = 0;
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.globalData.imgurl,
    showshare:false,
     //商品列表标签
    tabs: [{ name: "商品", nav_selected: 'nav_selected' }, 
    //{ name: "评价", nav_selected: '' }, { name: "商家", nav_selected: '' }
    ],   
    showCart: true,    //底部购物车
    category: [  // 左侧选项卡
      // { name: "商品1", cate_selected: 'cate_selected' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' },
      // { name: "商品2", cate_selected: '' }
    ],
    goods:[{
      id:12,
      name:'商品',
      picUrl:'/img/goodimg_03.png',
      price:'2550/天',
    }, {
      id: 12,
      name: '商品',
      picUrl: '/img/goodimg_03.png',
      price: '2550/天',
      }, {
        id: 12,
        name: '商品',
        picUrl: '/img/goodimg_03.png',
        price: '2550/天',
    }, {
      id: 12,
      name: '商品',
      picUrl: '/img/goodimg_03.png',
      price: '2550/天',
      }, {
        id: 12,
        name: '商品',
        picUrl: '/img/goodimg_03.png',
        price: '2550/天',
    }, {
      id: 12,
      name: '商品',
      picUrl: '/img/goodimg_03.png',
      price: '2550/天',
      }, {
        id: 12,
        name: '商品',
        picUrl: '/img/goodimg_03.png',
        price: '2550/天',
    }, {
      id: 12,
      name: '商品',
      picUrl: '/img/goodimg_03.png',
      price: '2550/天',
      }, {
        id: 12,
        name: '商品',
        picUrl: '/img/goodimg_03.png',
        price: '2550/天',
      },

    ],

  },
  onLoad: function (e) {
  },
  onShow: function () {
    this.getCate()
  },
  // 获取顶级分类
  getCate:function(){
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    var that = this;
    wx.request({
      url: app.globalData.url+'cate',
      success:function(res){
        var category = res.data
        for (var i = 0; i < category.length; i++){
          category[0].cate_selected = 'cate_selected'
        }
        that.getChildCate(category[0])
        that.setData({
          category: category
        })
      }
    })
  },
  // 选择一级分类
  setCate(e){
    var o = e.currentTarget.dataset
    var category = this.data.category
    for (var i = 0; i < category.length; i++) {
      category[i].cate_selected = ''
    }
    category[o.index].cate_selected = 'cate_selected'
    this.setData({
      category: category
    })
    wx.showLoading({
      title: '正在刷新',
      mask: true,
    })
    this.getChildCate(o)
  },
  // 加载子分类
  getChildCate: function (o){
    var that = this
    wx.request({
      url: app.globalData.url + 'cate_zi?id='+o.id,
      success: function (res) {
        var childcate = res.data
        that.setData({
           childcate:  childcate
        })
      },
      complete:function(){
        wx.hideLoading()
      }
    })
  },
  selectChildCate(e){
    var o = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/list/goodslist?cid='+o.id,
    })
  }
})